package com.atguigu.scala_01.chapter_03_IO

import java.io.{ByteArrayOutputStream, ObjectOutputStream, OutputStreamWriter, PrintWriter}
import java.net.Socket

object Client {
  def main(args: Array[String]): Unit = {
    val client = new Socket("localhost", 12345)
    val writer = new PrintWriter(new OutputStreamWriter(client.getOutputStream, "UTF-8"))
    val func=new Func()
    val bytes = serialize(func)
    writer.print(bytes)

    writer.flush()
    writer.close()
    client.close()

  }
  def serialize[Func](o:Func):Array[Byte]= {
    val bos = new ByteArrayOutputStream()
    val oos = new ObjectOutputStream(bos)
    oos.writeObject(o)
    oos.close()
    bos.toByteArray
  }
}

class Func extends java.io.Serializable {
  def double(num: Int): Int = {
    num * 2
  }
}
